//
//  MineHeaderView.m
//  BakeCenter
//
//  Created by Barnett Wu on 15/9/19.
//  Copyright (c) 2015年 Baked. All rights reserved.
//

#import "MineHeaderView.h"
#import "Masonry.h"
#define kSWidth [UIScreen mainScreen].bounds.size.width
#define kSHeight [UIScreen mainScreen].bounds.size.height

@implementation MineHeaderView

float width = 100;
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        self.userImageView = [[UIImageView alloc] init];
        self.userImageView.center = self.center;
        self.userImageView.userInteractionEnabled = YES;
        [self setUpUserImage:self.userImageView];

        UILabel *userNameLabel = [[UILabel alloc]init];
        userNameLabel.backgroundColor = [UIColor lightGrayColor];
        userNameLabel.text = @"雨夜乡涧";
        userNameLabel.textAlignment = NSTextAlignmentCenter;
        userNameLabel.font = [UIFont boldSystemFontOfSize:13.0];
        [self addSubview:userNameLabel];
        
        [self trimViewFrame:self.userImageView AndUserNameLabel:userNameLabel];
        
        
    }
    return self;
}

- (void)setUpUserImage:(UIImageView *)userImage
{
    userImage.layer.masksToBounds = YES;
    userImage.layer.borderWidth = 1.8;
    userImage.layer.backgroundColor = [[UIColor babyBlueColor] CGColor];
    userImage.layer.cornerRadius = width / 2;
    userImage.layer.borderColor = [[UIColor lightGrayColor] CGColor];

    [self addSubview:userImage];
}

- (void)trimViewFrame:(UIImageView *)userImageView AndUserNameLabel:(UILabel *)userNameLabel

{
    [self.userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.mas_top).offset(30);
        make.width.equalTo(@100);
        make.height.equalTo(@100);
        make.bottom.equalTo(userNameLabel.mas_top).offset(- 10);
    }];
    
    [userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.top.equalTo(self.userImageView.mas_bottom).offset(10);
        make.height.equalTo(@30);
        make.width.equalTo(@140);
    }
     ];


}

@end
